package es.xpt.ysf.commons.person.view;

import java.util.ArrayList;
import java.util.List;

import es.xpt.ysf.YSFException;
import es.xpt.ysf.commons.Names;
import es.xpt.ysf.commons.person.PersonSession;
import es.xpt.ysf.commons.person.model.Person;
import es.xpt.ysf.view.LocalDelegate;
import es.xpt.ysf.view.model.UserBean;

public class PersonDelegate extends LocalDelegate<PersonSession>{
	
	public PersonDelegate(UserBean user) {
		super(user);
	}
	
	public Person getPerson(String personId) throws YSFException {
		PersonSession ejb = connect(Names.PERSON);
		return ejb.getPerson(personId);
	}
	
	public List<Person> getEntityPeople(String entity, String entityId) throws YSFException {
		PersonSession ejb = connect(Names.PERSON);
		return ejb.getEntityPeople(entity, entityId);
	}
	
	public List<Person> searchPerson(String name ) throws YSFException {
		PersonSession ejb = connect(Names.PERSON);
		return ejb.searchPerson(name);
	}
	
	public List<Person> searchPerson(Person person ) throws YSFException {
		PersonSession ejb = connect(Names.PERSON);
		return ejb.searchPerson(person);
	}
	
	public ArrayList<String[]> searchDependentEntities(String personId ) throws YSFException {
		PersonSession ejb = connect(Names.PERSON);
		return ejb.searchDependentEntities(personId);
	}
	
	public List<String> searchEntityDependences(String personId, String entity ) throws YSFException {
		PersonSession ejb = connect(Names.PERSON);
		return ejb.searchEntityDependences(personId,entity);
	}
	
	public void addEntityPerson(String entityId, String entity, String personId, String role) throws YSFException {
		PersonSession ejb = connect(Names.PERSON);
		ejb.addEntityPerson(entityId, entity, personId, role);
	}
	
	public void removeEntityPerson(String entityId, String entity, String personId, String role) throws YSFException {
		PersonSession ejb = connect(Names.PERSON);
		ejb.removeEntityPerson(entityId, entity, personId, role);
	}
	
	
	public void updateEntityPerson(Person person) throws YSFException {
		PersonSession ejb = connect(Names.PERSON);
		ejb.updatePerson(person);
	}
	
	public void insertEntityPerson(Person person, String entity, String entityId) throws YSFException {
		PersonSession ejb = connect(Names.PERSON);
		ejb.insertPerson(person, entity, entityId);
	}
	public void updatePerson(Person person) throws YSFException {
		PersonSession ejb = connect(Names.PERSON);
		ejb.updatePerson(person);
	}
	
	public void deletePerson(String personId) throws YSFException {
		PersonSession ejb = connect(Names.PERSON);
		ejb.deletePerson(personId);
	}
	
	public void insertPerson(Person person) throws YSFException {
		PersonSession ejb = connect(Names.PERSON);
		ejb.insertPerson(person);
	}

	public List<String> deleteBatchPeople(List<String> listCodePeople) throws YSFException{
		PersonSession ejb = connect(Names.PERSON);
		return ejb.deleteBatchPeople(listCodePeople);
	}

}
